<template>
  <div class="login-box">
    <div class="owl" :class="{ password: isPasswordFocused }">
      <div class="hand"></div>
      <div class="hand hand-r"></div>
      <div class="arms">
        <div class="arm"></div>
        <div class="arm arm-r"></div>
      </div>
    </div>
    <div class="input-box">
      <input
        type="text"
        placeholder="账号"
        v-model="userAuth.account"
        :disabled="userAuth.isInput"
      />
      <input
        type="password"
        placeholder="密码"
        v-model="userAuth.password"
        :disabled="userAuth.isInput"
        @focus="handlePasswordFocus"
        @blur="handlePasswordBlur"
        @keyup.enter="handleLogin"
      />
      <button @click="handleLogin" :disabled="userAuth.isInput">登录</button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'

let userAuth = reactive({
  account: '',
  password: '',
  isInput: false,
})

let isPasswordFocused = ref(false)

let handlePasswordFocus = () => {
  isPasswordFocused.value = true
}

let handlePasswordBlur = () => {
  isPasswordFocused.value = false
}

let handleLogin = () => {
  if (!userAuth.isInput) {
    userAuth.isInput = true
    // 模拟登录逻辑
    setTimeout(() => {
      console.log('登录成功，重定向到其他页面')
      userAuth.isInput = false
    }, 2000)
  } else {
    userAuth.isInput = false
    console.log('登录失败，重新启用按钮和回车键')
  }
  console.log(userAuth.isInput)
}
</script>

<style scoped>
.login-box {
  /* 相对定位 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 320px;

  padding: 20px;
  box-shadow: 0 0 10px;
  border-radius: 15px;
  background: linear-gradient(200deg, #72afd3, #96fbc4);
  justify-content: center;
}
.input-box {
  /* 弹性布局 垂直排列 */
  display: flex;
  flex-direction: column;
}
.input-box input {
  height: 40px;
  border-radius: 3px;
  /* 缩进15像素 */
  text-indent: 15px;
  outline: none;
  border: none;
  margin-bottom: 15px;
}
.input-box input:focus {
  outline: 1px solid rgb(36, 197, 189);
}

.input-box button {
  width: 9em;
  height: 3em;
  border: none;
  border-radius: 30em;
  font-size: 15px;
  font-family: inherit;
  position: relative;
  overflow: hidden;
  z-index: 1;
  justify-content: center;
  text-align: center;
  outline: none;
  background-color: lightseagreen;
  margin: 0 auto; /* 水平居中 */
  display: block; /*使按钮成为块级元素 */
  transition: background-color 0.3s ease; /* 添加简单的背景色过渡效果 */
}

.input-box button {
  user-select: none;
}

.input-box button:focus {
  /* 焦点在的时候变化颜色 */
  background-color: #3cb371;
}

.input-box button:hover {
  /* 鼠标悬停颜色变化 */
  background-color: #3cb371;
}

/* 接下来是猫头鹰的样式 */
.owl {
  width: 211px;
  height: 108px;
  /* 背景图片 */
  background: url('@/assets/owl-login.png') no-repeat;
  /* 绝对定位 */
  position: absolute;
  top: -100px;
  /* 水平居中 */
  left: 50%;
  transform: translateX(-50%);
}
.owl .hand {
  width: 34px;
  height: 34px;
  border-radius: 40px;
  background-color: #472d20;
  /* 绝对定位 */
  position: absolute;
  left: 12px;
  bottom: -8px;
  /* 沿Y轴缩放0.6倍（压扁） */
  transform: scaleY(0.6);
  /* 动画过渡 */
  transition: 0.3s ease-out;
}
.owl .hand.hand-r {
  left: 170px;
}
.owl.password .hand {
  transform: translateX(42px) translateY(-15px) scale(0.7);
}
.owl.password .hand.hand-r {
  transform: translateX(-42px) translateY(-15px) scale(0.7);
}
.owl .arms {
  position: absolute;
  top: 58px;
  width: 100%;
  height: 41px;
  overflow: hidden;
}
.owl .arms .arm {
  width: 40px;
  height: 65px;
  position: absolute;
  left: 20px;
  top: 40px;
  background: url('@/assets/owl-login-arm.png') no-repeat;
  transform: rotate(-20deg);
  transition: 0.3s ease-out;
}
.owl .arms .arm.arm-r {
  transform: rotate(20deg) scaleX(-1);
  left: 158px;
}
.owl.password .arms .arm {
  transform: translateY(-40px) translateX(40px);
}
.owl.password .arms .arm.arm-r {
  transform: translateY(-40px) translateX(-40px) scaleX(-1);
}
</style>
